package com.lv.xulin.demopro;

import android.app.Activity;
import android.graphics.drawable.ClipDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;


public class ClipDrawableActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clip);

        ImageView imageView = (ImageView) findViewById(R.id.imgClip);
        final ClipDrawable clipDrawable;
        try {
            clipDrawable = (ClipDrawable) imageView.getDrawable();

            final Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    if (msg.what == 0x1233) {
                        clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
                    }
                }
            };
            final Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    Message msg = new Message();
                    msg.what = 0x1233;
                    handler.sendMessage(msg);
                    if (clipDrawable.getLevel() >= 10000) {
                        timer.cancel();
                    }
                }
            }, 0, 100);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
